package com.xin.di.uav.applet.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.xin.di.uav.applet.resp.OrderListRsResponse;
import com.xin.di.uav.applet.service.AppletOrderService;
import com.xin.di.uav.common.utils.BeanUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class AppletOrderServiceImpl implements AppletOrderService {

    @Override
    public List<OrderListRsResponse.Record> getOrderList(Integer page, Integer size) {
//        List<OrderPO> orderInfoList = orderInfoRest.getOrders(page, size);
        List<OrderListRsResponse.Record> rescueOrderResponses = new ArrayList<>();
//        //还要记录商品列表，总购买数量
//        if (!CollectionUtils.isEmpty(orderInfoList)) {
//            List<String> orderSns = orderInfoList.stream().map(orderInfo -> orderInfo.getTcWaybillNo()).collect(Collectors.toList());
//            List<OrderCommodity> orderCommodities = orderCommodityRest.getByOrderSns(orderSns);
//            List<Commodity> commodities = commodityMapper.selectBatchIds(orderCommodities.stream().map(orderCommodity -> orderCommodity.getCommodityId()).collect(Collectors.toList()));
//
//            orderInfoList.forEach(orderInfo -> {
//                RescueOrderResponse rescueOrderResponse = BeanUtil.copyProperties(orderInfo, RescueOrderResponse.class);
//                List<OrderCommodity> orderCommodityList = orderCommodities.stream().filter(orderCommodity -> orderCommodity.getOrderSn().equals(orderInfo.getTcWaybillNo())).collect(Collectors.toList());
//
//                List<String> commodityIds = orderCommodityList.stream().map(orderCommodity -> orderCommodity.getCommodityId()).collect(Collectors.toList());
//
//                List<Commodity> commodityList = commodities.stream().filter(commodity -> commodityIds.contains(commodity.getId())).collect(Collectors.toList());
//
//                Integer totalCnt = orderCommodityList.stream().map(orderCommodity -> orderCommodity.getCnt()).reduce(0, Integer::sum);
//                rescueOrderResponse.setTotalCnt(totalCnt);
//
//
//                List<CommodityResponse> commodityResponses = new ArrayList<>();
//                commodityList.forEach(commodity -> {
//                    List<OrderCommodity> orderCommodities1 = orderCommodityList.stream().filter(orderCommodity -> orderCommodity.getCommodityId().equals(commodity.getId())).collect(Collectors.toList());
//                    CommodityResponse commodityResponse = BeanUtil.copyProperties(commodity, CommodityResponse.class);
//                    if (!CollectionUtils.isEmpty(orderCommodities1)) {
//                        commodityResponse.setCnt(orderCommodities1.get(0).getCnt());
//                        commodityResponse.setPrice(orderCommodities1.get(0).getPrice());
//                        commodityResponse.setName(orderCommodities1.get(0).getName());
//                        commodityResponse.setIntroduction(orderCommodities1.get(0).getIntroduction());
//                        commodityResponse.setImages(orderCommodities1.get(0).getImages());
//                    }
//                    commodityResponses.add(commodityResponse);
//                });
//
//                rescueOrderResponse.setCommodityResponses(commodityResponses);
//
//
//                rescueOrderResponses.add(rescueOrderResponse);
//            });
//        }
        return rescueOrderResponses;
    }
}
